<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-5-26
 * Time: 上午9:20
 */
class Mmessage extends CI_MODEL
{
    function __construct()
    {
        parent::__construct();
    }


    /**
     * 获用系统信件
     */
    function getMessagesByUid($uid)
    {
        $query = $this->db->get_where('tbmessage',array('uid'=>$uid));
        return $query->result_array();
    }

    function getMessageByid($id)
    {
        $query = $this->db->get_where('tbmessage',array('id'=>$id),1);
        return $query->row_array();
    }

    /**
     * 发送消息
     * @param $title
     * @param int $sendUid
     * @param $uid
     * @param $content
     * @return mixed
     */
    function sendMessage($title,$sendUid=0,$uid,$content)
    {
        $data = array(
            'title' => "$title" ,
            'uid' => $uid ,
            'content' => "$content",
            'create_time'=>time(),
            'sendUid'=>$sendUid
        );

        $this->db->insert('tbmessage', $data);
        return $this->db->insert_id();
    }

}